package com.xyw.his00.service.Impl.dbImpl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xyw.his00.dto.AreaDTO;
import com.xyw.his00.mapper.AreaMapper;
import com.xyw.his00.pojo.dbpojo.Area;
import com.xyw.his00.service.dbservice.AreaService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class AreaServiceImpl extends ServiceImpl<AreaMapper, Area> implements AreaService  {
    @Autowired
    private AreaMapper areaMapper;
    @Resource
    private RedisTemplate<String,Object> redisTemplate ;


    @Override
    public List<AreaDTO> selectProvince() {
      Object o=  redisTemplate.opsForValue().get("Province");
      if(o==null) {
          List<AreaDTO> areaDTOS = areaMapper.selectProvince();
          if (areaDTOS != null) {
              redisTemplate.opsForValue().set("Province", areaDTOS);

          }
          return areaMapper.selectProvince();
      }else{
          return null;
      }
    }

    @Override
    public List<AreaDTO> selectCity() {
        Object o=  redisTemplate.opsForValue().get("City");
        if(o==null) {
            List<AreaDTO> areaDTOS = areaMapper.selectCity();
            if (areaDTOS != null) {
                redisTemplate.opsForValue().set("City", areaDTOS);

            }
            return areaMapper.selectCity();
        }else{
            return null;
        }
    }

    @Override
    public List<AreaDTO> selectRegion() {
        Object o=  redisTemplate.opsForValue().get("Region");
        if(o==null) {
            List<AreaDTO> areaDTOS = areaMapper.selectRegion();
            if (areaDTOS != null) {
                redisTemplate.opsForValue().set("Region", areaDTOS);

            }
            return areaMapper.selectRegion();
        }else{
            return null;
        }
    }

    @Override
    public List<AreaDTO> selectCountry() {
        Object o=  redisTemplate.opsForValue().get("Country");
        if(o==null) {
            List<AreaDTO> areaDTOS = areaMapper.selectCountry();
            if (areaDTOS != null) {
                redisTemplate.opsForValue().set("Country", areaDTOS);
            }
            return areaMapper.selectCountry();
        }else{
            return null;
        }
    }
}
